Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: about-us add Carousel #21

Merged
merged 1 commit into from
Sep 22, 2024
Merged

feat: about-us add Carousel #21

merged 1 commit into from
Sep 22, 2024

Conversation

bessyhuang
Copy link
Contributor

@bessyhuang bessyhuang commented Sep 9, 2024

Carousel 待修

@rileychh
Copy link
Member

rileychh commented Sep 9, 2024

diff --git a/components/FlickrCarousel.vue b/components/FlickrCarousel.vue
index 6d7f83a..c658985 100644
--- a/components/FlickrCarousel.vue
+++ b/components/FlickrCarousel.vue
@@ -1,19 +1,11 @@
-<script>
+<script setup>
 import { Swiper, SwiperSlide } from 'swiper/vue'
 import 'swiper/swiper-bundle.css'
+import imageA from '#assets/images/1.jpg'
+import imageB from '#assets/images/2.jpg'
+import imageC from '#assets/images/3.jpg'
 
-export default {
-  components: { Swiper, SwiperSlide },
-  data() {
-    return {
-      images: [
-        '/images/image1.jpg',  // Replace with your image paths
-        '/images/image2.jpg',
-        '/images/image3.jpg',
-      ],
-    }
-  },
-}
+const images = [imageA, imageB, imageC]
 </script>
 
 <template>
@@ -24,7 +16,7 @@ export default {
   >
     <SwiperSlide
       v-for="(src, index) in images"
-      :key="index"
+      :key="src"
     >
       <img
         :alt="`Image ${index + 1}`"

這樣應該就可以動了!

  1. 改用 <script setup>
  2. 靜態匯入圖片(匯入的是打包 (build) 後的路徑)
  3. key 改成用 src 本身,因為 key 的用途是追蹤順序,如果用 index 作為 key 的話就沒有用了 😅

@bessyhuang bessyhuang self-assigned this Sep 10, 2024
@bessyhuang
Copy link
Contributor Author

+import imageA from '#assets/images/image1.jpg'
+import imageB from '#assets/images/image2.jpg'
+import imageC from '#assets/images/image3.jpg'

components/FlickrCarousel.vue 我嘗試根據第 1、3 點修改,但不確定第 2 點的意思。😅

第 2 點意思是指需要手動將圖片的位置改放到 /assets 底下(也就是 /assets/images/image1.jpg)嗎?
還是說,圖片的位置仍然放在 /docs/public/images/image1.jpg,再去跑 pnpm run build 呢?

@bessyhuang
Copy link
Contributor Author

沒事了,我成功試出來了!🤣

手動將圖片的位置改放到 /assets 底下(也就是 /assets/images/image1.jpg),再去跑 pnpm run build
image

@rileychh
Copy link
Member

放在 assets 底下可以讓 Vite 決定檔案名稱和格式,製作更有效率的圖片,但是需要用 import 來取得 Vite 產生的檔案名稱。如果需要固定的 URL,像是 favicon.ico 或是 robots.txt 這種檔案,就可以放在 public 底下。

BTW,在開發時用 pnpm run dev 可以即時看到修改,更方便喔。

@mirumodapon
Copy link
Contributor

嗨!Bessy 這些圖片看起來好肥好大,建議可以先縮到適合的大小然後再壓過一遍

推薦一個線上工具https://squoosh.app

@rileychh
Copy link
Member

考量到現在的圖片大小不到 300px 高(好像可以再大一些 ><)可以轉換成 100 kB 以下的 WebP 檔案,應該還是能保有很好的品質!

@bessyhuang
Copy link
Contributor Author

我利用咪路提供的 https://squoosh.app/ 工具,將照片 Quality 調在 10 ~ 20 之間,約莫 200 kB 左右的 WebP 檔案。
目前,Carousel 修好 bug 能自動輪播,內容的部分也更新了 😀
有空的話,再麻煩幫我看看有哪裡需要調整,謝謝~

@bessyhuang
Copy link
Contributor Author

接下來,我會嘗試將圖和文字弄在一起,類似 SITCON 支持我們 這樣。

@rileychh
Copy link
Member

要不要考慮把 9a0a7f9(第二個)合併進 c7489c6(第三個)?這樣就不會有簽入大相片的 Git 歷史,節省日後的 clone 時間。

@bessyhuang
Copy link
Contributor Author

我把 commit 拆掉再重新 push 囉!感謝 Riley 建議~

記錄一下作法:

切換到目標分支
$ git checkout [分支名稱]

檢視提交的歷史記錄
$ git log

拆掉倒數兩個 commit (保留更改,但刪除已提交的歷史記錄),亦即透過 git reset 返回原本倒數第三個 commit 的狀態
$ git reset --soft HEAD~2

將第二個和第三個 commit 的變動合併為一個新的 commit
$ git commit --amend

強制更新遠端分支
$ git push --force

@rileychh
Copy link
Member

還有另外一種可能更方便的做法,就是用 interactive rebase (git rebase -i),然後把 pick 改成 squash 喔!

@mirumodapon
Copy link
Contributor

好了記得要打開 pr 喔!

@bessyhuang
Copy link
Contributor Author

還有另外一種可能更方便的做法,就是用 interactive rebase (git rebase -i),然後把 pick 改成 squash 喔!

好的,我下次用這方式試試看,謝謝!

@bessyhuang
Copy link
Contributor Author

好了記得要打開 pr 喔!

我先把這版發 PR

@bessyhuang bessyhuang marked this pull request as ready for review September 22, 2024 14:59
@bessyhuang bessyhuang merged commit 3d642bb into main Sep 22, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants